<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../include/admincontent.jsp" %>

<div id="location">当前位置：首页 > 招聘方案管理 > 修改招聘方案</div>
<div id="Content">
    <form id="Validform" method="post" action="/Project/EditAction">
        <input type="hidden" name="project.id" value="${project.id}"/>
        <input type="hidden" name="ptype" value="${ptype}"/>
        <div class="btnbar">
            <button type="submit" class="save">保 存</button>
            <button type="button" class="back" onclick="javascript:history.go(-1);">返 回</button>
        </div>
        <table class="treeTable inputform">
            <thead>
            <tr>
                <td colspan="4"><b>基本信息</b></td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td width="65">方案名称：</td>
                <td>
                    <div style="width:300px;"><input type="text" name="project.pname" value="${project.pname}"
                                                     datatype="*" nullmsg="方案名称不能为空！"/></div>
                </td>
            </tr>
            <tr>
                <td>招聘方式：</td>
                <td>
                    <div class="radio disables" >
                        <span rel="1" fdata="1">内部招聘</span>
                       <%-- <span rel="2" fdata="2">中专校园招聘</span>--%>
                        <span rel="3" fdata="3">社会招聘</span>
                        <%--<span rel="4" fdata="4">内部招聘</span>--%>
                        <input type="hidden" id="recruittype" name="project.recruittype" value="${project.recruittype}"
                               datatype="*" nullmsg="招聘方式不能为空！">
                    </div>
                </td>
            </tr>
            </tbody>
        </table>

        <!-- 统一流程配置,各个方案可自定义流程 -->
        <table class="treeTable inputform" style="margin-top:5px;" id="flows">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>
            ${flows}
            </tbody>
        </table>

        <%--
        <!-- 高校校园招聘流程 -->
        <table class="treeTable inputform" style="margin-top:5px;" id="flow1">
            <thead>
            <tr>
                <td><b>实施流程</b></td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>简历筛选&emsp;>&emsp;面试&emsp;>&emsp;背景调查&emsp;>&emsp;体检&emsp;>&emsp;岗位分配&emsp;>&emsp;录用</td>
            </tr>
            </tbody>
        </table>

        <!-- 中专校园招聘流程 -->
        <table class="treeTable inputform" style="margin-top:5px;display:none;" id="flow2">
            <thead>
            <tr>
                <td><b>实施流程</b></td>
            </tr>
            </thead>
            <tbody>
            <!-- <tr><td>毕业生推荐&emsp;>&emsp;初审&emsp;>&emsp;投简历&emsp;>&emsp;面试&emsp;>&emsp;背景调查&emsp;>&emsp;体检&emsp;>&emsp;岗位分配&emsp;>&emsp;实习&emsp;>&emsp;录用</td></tr> -->
            <tr>
                <td>毕业生推荐&emsp;>&emsp;初审&emsp;>&emsp;投简历&emsp;>&emsp;录用</td>
            </tr>
            </tbody>
        </table>

        <!-- 社会招聘流程 -->
        <table class="treeTable inputform" style="margin-top:5px; display:none;" id="flow3">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>${szflows}</tbody>
        </table>

        <!-- 内部招聘流程 -->
        <table class="treeTable inputform" style="margin-top:5px; display:none;" id="flow4">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>${nzflows}</tbody>
        </table>--%>

        <!-- 招聘岗位 -->
        <table class="treeTable inputform" id="jobtb" style="margin-top:5px;">
            <thead>
            <tr>
                <td colspan="10"><b>招聘岗位</b></td>
            </tr>
            <tr>
                <td width="40">序号</td>
                <td>岗位名称</td>
                <td width="120">招聘人数</td>
                <td width="120">年龄</td>
                <td width="120">工作年限</td>
                <td width="120">学历</td>
                <td width="120">专业</td>
                <td width="120">性别</td>
                <td width="40">
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody id="result"></tbody>
        </table>

        <!-- 高校校园招聘地区 -->
       <%-- <table class="treeTable inputform" id="areagx" style="margin-top:5px;">
            <thead>
            <tr>
                <td><b>招聘地区</b></td>
            </tr>
            </thead>
            <tbody id="arearst">
            <tr>
                <td>
                    <div class=radio1>${areas}</div>
                </td>
            </tr>
            </tbody>
        </table>--%>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        getProJobs();

        //初始化单选控件选中值
        $('select').each(function () {
            $(this).val($(this).prev().val());
        });

        var recruittype=$('#recruittype').val();
        if(!!recruittype){
            $('#recruittype').prevAll().each(function () {
                if ($(this).attr('rel') == recruittype) {
                    $(this).addClass('checked');
                }
            });
        }
        /*$('.radio input[type=hidden]').each(function () {
            var val = $(this).val();

            (this).parent().find('span').each(function () {
                if ($(this).attr('rel') == val) {
                    $(this).addClass('checked');
                    //采用通用流程不在进行显示屏蔽
                    //$('table[id^=flow]').hide();
                    //$('#flow' + $(this).attr('fdata')).show();
                }
            });
        });*/

        showJobList($('#recruittype').val());

        //选择招聘方式
        $('.radio span').click(function () {
            if (!$(this).parent().hasClass('disables')) {
                $('table[id^=flow]').hide();
                $('#flow' + $(this).attr('fdata')).show();

                showJobList($(this).attr('fdata'));
            }
        });

        //添加通用流程
        $(document).delegate('#flows button.add', 'click', function () {
            var temp = '<tr><td>2</td><td><div><select name="flow[1].fid"><option value="1">笔试</option><option value="2">资料审核</option><option value="3">面试</option><option value="4">实作</option><option value="5">体检</option><option value="6">背景调查</option></select></div></td>';
            temp += '<td><div><input type="text" name="flow[1].nickname" datatype="*" nullmsg="流程别名不能为空！"></div></td>';
            temp += '<td><button type="button" onfocus="blur()" class="del"></button></td></tr>';

            $('#flows tbody tr:last').before(temp);
            $('#flows tbody tr:last').prev().find('td:eq(2) input').val($('#flows tbody tr:last').prev().find('td:eq(1) select option:checked').text());
            setFlowStyle();
        });

        //删除流程
        $(document).delegate('#flows button.del', 'click', function () {
            $(this).parent().parent().remove();
            setFlowStyle();
        });

        //流程别名
        //流程别名
        $(document).delegate('#flows select', 'change', function () {
            $(this).parent().parent().next().find('input').val($(this).find('option:checked').text());
            $(this).prev().val($(this).val());
        });

        //添加招聘岗位
        $('#jobtb button.add').click(function () {
            openLayer('添加招聘岗位', '/Project/AddJob?pid=${project.id}&ptype='+$('#recruittype').val(), '98%', '98%');
        });

        //删除招聘岗位
        $(document).delegate('#jobtb button.del', 'click', function () {
            var _obj = $(this);
            layer.confirm('确定要删除该岗位吗？', {
                btn: ['是', '否']
            }, function () {
                var url = '/Project/delJobAction?id=' + _obj.prev().val();
                postAjax(url, null, function (data) {
                    if (data.state) {
                        _obj.parent().parent().remove();
                        setJobStyle();
                    } else {
                        $.Showmsg(data.Message);
                    }
                });
                layer.closeAll();
            }, function () {
                layer.closeAll();
            });
        });

        //修改招聘岗位
        $(document).delegate('#jobtb button.edit', 'click', function () {
            var _obj = $(this);
            var url = '/Project/EditJob?id=' + _obj.next().val();
            openLayer('修改招聘岗位', url, '98%', '98%');
        });



    });

    //设置流程表单信息
    function setFlowStyle() {
        //社会招聘
        $('#flows tbody tr').each(function (index) {
            $(this).find('td:first').html(index + 1);
            if (index > 0 && index < $('#flows tbody tr').length - 1) {
                $(this).find('td:eq(1) select').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            } else {
                $(this).find('td:eq(1) input').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            }
        });

       /* //内部招聘
        $('#flow4 tbody tr').each(function (index) {
            $(this).find('td:first').html(index + 1);
            if (index > 1 && index < $('#flow4 tbody tr').length - 1) {
                $(this).find('td:eq(1) select').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            } else {
                $(this).find('td:eq(1) input').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            }
        });*/
    }

    //设置岗位表单信息
    function setJobStyle() {
        $('#result tr').each(function (index) {
            $(this).find('td:first').html(index + 1);
        });
    }

    //显示或隐藏岗位列表
    function showJobList(str) {
        $('#jobtb').hide();
        $('#areagx').hide();
        /*if (str == '2'){
            $('#jobtb').show();
            $('#areagx').show();
        }else{
            $('#jobtb').show();
            $('#areagx').show();
        }*/
        $('#jobtb').show();
    }

    function getProJobs() {
        getAjax('/Project/getProJobs?pid=${project.id}', null, function (data) {
            $('#result').html(data);
        });
    }

</script>
</body>
</html>